package com.to_door_recycle.common.util;

import com.to_door_recycle.common.enums.ExceptionStatusEnum;
import com.to_door_recycle.common.exception.auth.AuthException;
import com.to_door_recycle.common.exception.auth.UnLoginException;
import com.to_door_recycle.common.exception.auth.UsernameOrPasswordException;
import com.to_door_recycle.common.exception.biz.BizException;
import com.to_door_recycle.common.exception.data.DataException;
import com.to_door_recycle.common.exception.data.ParamException;
import com.to_door_recycle.common.exception.data.RequestDataException;

public class ExceptionUtil {
    //  ============== 业务异常 ==============
    public static void throwBizException() {
        throw new BizException(ExceptionStatusEnum.BIZ_EXCEPTION);
    }
    public static void throwBizException(String message) {
        throw new BizException(ExceptionStatusEnum.BIZ_EXCEPTION.getCode(), message);
    }
    public static void throwBizException(String message, Integer code) {
        throw new BizException(code, message);
    }
    public static void throwBizExceptionIf(boolean condition, String message) {
        if (condition) {
            throw new BizException(ExceptionStatusEnum.BIZ_EXCEPTION.getCode(), message);
        }
    }
    public static void throwBizExceptionIf(boolean condition, String message, Integer code) {
        if (condition) {
            throw new BizException(code, message);
        }
    }

    //  ============== 认证异常 ==============
    public static void throwAuthException() {
        throw new AuthException(ExceptionStatusEnum.AUTH_EXCEPTION);
    }
    public static void throwAuthException(String message) {
        throw new AuthException(ExceptionStatusEnum.AUTH_EXCEPTION.getCode(), message);
    }
    public static void throwAuthException(String message, Integer code) {
        throw new AuthException(code, message);
    }
    public static void throwAuthExceptionIf(boolean condition, String message) {
        if (condition) {
            throw new AuthException(ExceptionStatusEnum.AUTH_EXCEPTION.getCode(), message);
        }
    }
    public static void throwAuthExceptionIf(boolean condition, String message, Integer code) {
        if (condition) {
            throw new AuthException(code, message);
        }
    }

    //  ============== 未登录异常 ==============
    public static void throwUnLoginException() {
        throw new UnLoginException(ExceptionStatusEnum.UNLOGIN_EXCEPTION);
    }
    public static void throwUnLoginException(String message) {
        throw new UnLoginException(ExceptionStatusEnum.UNLOGIN_EXCEPTION.getCode(), message);
    }
    public static void throwUnLoginException(String message, Integer code) {
        throw new UnLoginException(code, message);
    }
    public static void throwUnLoginExceptionIf(boolean condition, String message) {
        if (condition) {
            throw new UnLoginException(ExceptionStatusEnum.UNLOGIN_EXCEPTION.getCode(), message);
        }
    }
    public static void throwUnLoginExceptionIf(boolean condition, String message, Integer code) {
        if (condition) {
            throw new UnLoginException(code, message);
        }
    }


    //  ============== 登录信息有误异常 ==============
    public static void throwUsernameOrPasswordException() {
        throw new UsernameOrPasswordException(ExceptionStatusEnum.USERNAME_OR_PASSWORD_EXCEPTION);
    }
    public static void throwUsernameOrPasswordException(String message) {
        throw new UsernameOrPasswordException(ExceptionStatusEnum.USERNAME_OR_PASSWORD_EXCEPTION.getCode(), message);
    }
    public static void throwUsernameOrPasswordException(String message, Integer code) {
        throw new UsernameOrPasswordException(code, message);
    }
    public static void throwUsernameOrPasswordExceptionIf(boolean condition, String message) {
        if (condition) {
            throw new UsernameOrPasswordException(ExceptionStatusEnum.USERNAME_OR_PASSWORD_EXCEPTION.getCode(), message);
        }
    }
    public static void throwUsernameOrPasswordExceptionIf(boolean condition, String message, Integer code) {
        if (condition) {
            throw new UsernameOrPasswordException(code, message);
        }
    }


    //  ============== 数据异常 ==============
    public static void throwDataException() {
        throw new AuthException(ExceptionStatusEnum.DATA_EXCEPTION);
    }
    public static void throwDataException(String message) {
        throw new DataException(ExceptionStatusEnum.DATA_EXCEPTION.getCode(), message);
    }
    public static void throwDataException(String message, Integer code) {
        throw new DataException(code, message);
    }
    public static void throwDataExceptionIf(boolean condition, String message) {
        if (condition) {
            throw new DataException(ExceptionStatusEnum.DATA_EXCEPTION.getCode(), message);
        }
    }
    public static void throwDataExceptionIf(boolean condition, String message, Integer code) {
        if (condition) {
            throw new DataException(code, message);
        }
    }


    //  ============== 参数异常 ==============
    public static void throwParamException() {
        throw new ParamException(ExceptionStatusEnum.PARAM_EXCEPTION);
    }
    public static void throwParamException(String message) {
        throw new ParamException(ExceptionStatusEnum.PARAM_EXCEPTION.getCode(), message);
    }
    public static void throwParamException(String message, Integer code) {
        throw new ParamException(code, message);
    }
    public static void throwParamExceptionIf(boolean condition, String message) {
        if (condition) {
            throw new ParamException(ExceptionStatusEnum.PARAM_EXCEPTION.getCode(), message);
        }
    }
    public static void throwParamExceptionIf(boolean condition, String message, Integer code) {
        if (condition) {
            throw new ParamException(code, message);
        }
    }



    //  ============== 请求数据异常 ==============
    public static void throwRequestDataException() {
        throw new RequestDataException(ExceptionStatusEnum.REQUEST_DATA_EXCEPTION);
    }
    public static void throwRequestDataException(String message) {
        throw new RequestDataException(ExceptionStatusEnum.REQUEST_DATA_EXCEPTION.getCode(), message);
    }
    public static void throwRequestDataException(String message, Integer code) {
        throw new RequestDataException(code, message);
    }
    public static void throwRequestDataExceptionIf(boolean condition, String message) {
        if (condition) {
            throw new RequestDataException(ExceptionStatusEnum.REQUEST_DATA_EXCEPTION.getCode(), message);
        }
    }
    public static void throwRequestDataExceptionIf(boolean condition, String message, Integer code) {
        if (condition) {
            throw new RequestDataException(code, message);
        }
    }







}
